package cn.edu.ctbu.studentmanage.service.impl;

import cn.edu.ctbu.studentmanage.domain.Lecture;
import cn.edu.ctbu.studentmanage.repository.LectureRepository;
import cn.edu.ctbu.studentmanage.service.LectureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LectureImplService implements LectureService {
    @Autowired
    private LectureRepository lectureRepository;
    /**
     * 查询所有的授课信息
     * @return
     */
    public List<Lecture> findAll(){

        return lectureRepository.findAll();
    }
    /**
     * 分页
     * @param pageable
     * @return
     */
    public Page<Lecture> findAll(Pageable pageable) {

        return lectureRepository.findAll(pageable);
    }
    /**
     * 分页加动态查询
     * @param lectureExample
     * @param pageable
     * @return
     */
    public Page<Lecture> findAll(Example<Lecture> lectureExample, Pageable pageable){
        return lectureRepository.findAll(lectureExample,pageable);
    }
    /**
     * 根据id获取某一授课信息
     * @param lid
     * @return
     */
    public Lecture getByLid(Integer lid){

        return lectureRepository.findById(lid).orElse(null);
    }
    /**
     * 更新授课信息
     * @param lecture
     */
    public void update(Lecture lecture){
        lectureRepository.save(lecture);
    }
    /**
     * 根据id删除某一授课信息
     * @param lid
     */
    public void delete(Integer lid){
        lectureRepository.deleteById(lid);
    }
    /**
     * 插入新的授课信息
     * @param lecture
     */
    public void Insert(Lecture lecture){
        lectureRepository.save(lecture);
    }

}
